# _*_ coding : utf-8 _*_
# @Time : 2023/3/17 0017 14:29
# @Author : 菜鸟王小二
# @File : 27_selenium_headless无界面使用
# @Project : python爬虫
import time

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By

# 未执行成功，报以下版本错误：
# selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 105
def share_browser():
    options = webdriver.ChromeOptions()
    options.add_argument('--headless')
    options.add_argument('disable-gpu')

    driver = webdriver.Chrome(options=options)

    return driver


driver = share_browser()
driver.get('https://www.baidu.com')

driver.find_element(By.ID, 'kw').send_keys('周杰伦')
time.sleep(2)
driver.find_element(By.ID, 'su').click()
time.sleep(2)

driver.save_screenshot('Jay.jpg')
driver.quit()
